package com.jintian.smart.platform.system.mapper;

import com.jintian.smart.kernel.orm.mapper.IBaseExtMapper;
import com.jintian.smart.base.api.system.entity.EmployeeEntity;
import com.jintian.smart.base.api.system.form.EmployeeQueryForm;
import com.jintian.smart.base.api.system.view.EmployeeVO;
import org.beetl.sql.core.page.PageResult;
import org.beetl.sql.core.query.LambdaQuery;
import org.beetl.sql.mapper.annotation.Mapper;
import org.beetl.sql.mapper.annotation.Param;
import org.beetl.sql.mapper.annotation.SqlResource;

import java.util.List;

/**
 * 员工 dao
 */
@Mapper
@SqlResource("system.Employee")
public interface EmployeeMapper extends IBaseExtMapper<EmployeeEntity> {
    /**
     * 查询员工列表
     */
    PageResult<EmployeeVO> queryEmployee(EmployeeQueryForm queryForm, @Param("departmentIdList") List<Long> departmentIdList);

    /**
     * 查询员工
     */
    List<EmployeeVO> selectEmployeeByDisabledAndDeleted(@Param("disabledFlag") Integer disabledFlag, @Param("deletedFlag") Integer deletedFlag);

    /**
     * 获取所有
     */
    List<Long> getEmployeeId(@Param("leaveFlag") Integer leaveFlag, @Param("deletedFlag") Integer deletedFlag);

    /**
     * 获取某个部门员工数
     */
    default long countByDepartmentId(Long departmentId, Integer deletedFlag) {
        LambdaQuery<EmployeeEntity> query = this.createLambdaQuery().andEq(EmployeeEntity::getDepartmentId, departmentId);
        if (deletedFlag != null) {
            query.andEq(EmployeeEntity::getDeletedFlag, deletedFlag);
        }
        return query.count();
    }
}